package com.eryos.android.holidaybudget.tools;

import android.app.ProgressDialog;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;

/**
 * Project :  HolidayBudget
 * Author :   Olivier Combe 
 * URL :      http://eryos.fr/HolidayBudget/
 *
 * Copyright (C) 2011 - Olivier Combe 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *
 */

public class WaitingMessage {

	private static ProgressDialog waitingDialog;
	private static Context context;
	
	public static void init(Context _context){
		context = _context;
	}

    /**
     * Show a waiting popup
     */
    public static void showWaitingMessage(){
    	try {
    		Log.d("WaitingMessage", "show waiting message : "+waitingDialog);
    		waitingDialog = new ProgressDialog(context);
			waitingDialog.setMessage("Please wait ..."/*context.getResources().getString(R.string.home_waiting)*/);
			waitingDialog.setIndeterminate(true);
			waitingDialog.setCancelable(false);
			waitingDialog.show();
    	} catch (IllegalStateException e) {
	    		Log.e("WaitingMessage", "showWaitingMessage 2 : Error : ",e);
    	} catch (Exception e) {
    		Log.e("WaitingMessage", "showWaitingMessage : Error : ",e);
		}
    }
        
    /**
     * hide the waiting popup
     */
    public static void hideWaitingMessage(){
    	try {
			if ( waitingDialog != null ) {
				Log.d("WaitingMessage", "dismiss waiting message : "+waitingDialog);
				waitingDialog.dismiss();
				waitingDialog.cancel();
				waitingDialog = null;
			}
		} catch (Exception e) {
			Log.e("WaitingMessage", "hideWaitingMessage : Error : ",e);
		}
    }

    /**
     * Hide the waiting popup and show a Toast with argument value
     * @param ID
     */
    public static void hideWaitingMessage(int ID){
    	hideWaitingMessage();
    	Toast.makeText(context, ID, Toast.LENGTH_SHORT).show();
    }
    
    public static void hideWaitingMessage(String text){
    	hideWaitingMessage();
    	Toast.makeText(context, text, Toast.LENGTH_LONG).show();
    }

	
}
